home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Activation / Activator.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  1.3 KB  |  82 lines  |  [TEXT/CWIE]

  1. // Activator.cp
  2.  
  3. #ifndef Activator_h
  4. #include "Activator.h"
  5. #endif
  6. #ifndef Focus_h
  7. #include "Focus.h"
  8. #endif
  9. #ifndef ContextMaintainer_h
  10. #include "ContextMaintainer.h"
  11. #endif
  12.  
  13. Activator::Activator( Focus& focus )
  14.   : Enableable( !focus.Active() ),
  15.          // We can't call Activate() yet, so we start disabled
  16.          // if we're connected to an active focus.
  17.      active( false ),
  18.      focusActive( focus.Active() ),
  19.      link( this )
  20.   {
  21.     focus.activators.Add( link, afterEnd );
  22.   }
  23.  
  24. Activator::~Activator()
  25.   {
  26.   }
  27.  
  28. void Activator::FocusActivated()
  29.   {
  30.     Assert( !focusActive );
  31.     Assert( !active );
  32.     
  33.     focusActive = true;
  34.     if ( Enabled() )
  35.       {
  36.         ContextMaintainer oldContext( *this );
  37.         active = true;
  38.         Activate();
  39.       }
  40.   }
  41.  
  42. void Activator::FocusDeactivated()
  43.   {
  44.     Assert( focusActive );
  45.     Assert( active == Enabled() );
  46.     
  47.     focusActive = false;
  48.     if ( Enabled() )
  49.       {
  50.         ContextMaintainer oldContext( *this );
  51.         active = false;
  52.         Deactivate();
  53.       }
  54.   }
  55.  
  56. void Activator::BeEnabled()
  57.   {
  58.     Assert( !active );
  59.  
  60.     if ( focusActive )
  61.       {
  62.         ContextMaintainer oldContext( *this );
  63.         active = true;
  64.         Activate();
  65.       }
  66.   }
  67.  
  68. void Activator::BeDisabled()
  69.   {
  70.     Assert( focusActive == active );
  71.     
  72.     if ( focusActive )
  73.       {
  74.         ContextMaintainer oldContext( *this );
  75.         active = false;
  76.         Deactivate();
  77.       }
  78.   }
  79.  
  80. #include "ListLink.cp"
  81. #include "ListOf.cp"
  82.